import time

from selenium.common.exceptions import TimeoutException


def request_wait(method, timeout, waitTime=1, message=""):
    end_time = time.time() + timeout
    while True:
        value = method()
        if value:
            return 0
        time.sleep(waitTime)
        if time.time() > end_time:
            break
    raise TimeoutException(message)